﻿namespace BusinessLogic
{
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Web;
    using DataAccessLogic;

    public class Address : Table
    {
        #region Fields
        private AddressType _addressType;        
        private string _addressBlock;
        private string _postCode;
        private string _city;
        private State _state;
        private Country _country;
        private bool _isPrimary;
        private bool _isActive;
        #endregion

        #region Methods
        public static Address GetByConstituentID(Guid constituentID)
        {
            return DataAccess.Address_DA.GetByConstituentID(constituentID);
        }

        public static Address GetPrimaryByConstituentID(Guid constituentID)
        {
            return DataAccess.Address_DA.GetPrimaryByConstituentID(constituentID);
        }

        public static List<Address> GetAllByConstituentID(Guid constituentID)
        {
            return DataAccess.Address_DA.GetAllByConstituentID(constituentID);            
        }
        #endregion

        #region Properties
        [SQLParameter(ColumnName = "ISACTIVE", SQLDoWhat = SQLDoWhatEnum.Get)]
        [SQLParameter(ParameterName = "@ISACTIVE", SQLDoWhat = SQLDoWhatEnum.Create, StoredProcedure = StoredProcedures.USP_ADDRESS_CREATE)]
        public bool IsActive
        {
            get
            {
                return _isActive;
            }
            set
            {
                _isActive = value;
            }
        }

        [SQLParameter(ColumnName = "ISPRIMARY", SQLDoWhat = SQLDoWhatEnum.Get)]
        [SQLParameter(ParameterName = "@ISPRIMARY", SQLDoWhat = SQLDoWhatEnum.Create, StoredProcedure = StoredProcedures.USP_ADDRESS_CREATE)]
        public bool IsPrimary
        {
            get
            {
                return _isPrimary;
            }
            set
            {
                _isPrimary = value;
            }
        }

        [SQLParameter(IsClass = true, SQLDoWhat = SQLDoWhatEnum.Create)]
        public AddressType AddressType
        {
            get
            {
                return _addressType;
            }
            set
            {
                _addressType = value;
            }
        }

        [SQLParameter(ColumnName = "ADDRESSBLOCK", SQLDoWhat = SQLDoWhatEnum.Get)]
        [SQLParameter(ParameterName = "@ADDRESSBLOCK", SQLDoWhat = SQLDoWhatEnum.Create, StoredProcedure = StoredProcedures.USP_ADDRESS_CREATE)]
        public string AddressBlock
        {
            get
            {
                return _addressBlock;
            }
            set
            {
                _addressBlock = value;
            }
        }

        [SQLParameter(ColumnName = "CITY", SQLDoWhat = SQLDoWhatEnum.Get)]
        [SQLParameter(ParameterName = "@CITY", SQLDoWhat = SQLDoWhatEnum.Create, StoredProcedure = StoredProcedures.USP_ADDRESS_CREATE)]
        public string City
        {
            get
            {
                return _city;
            }
            set
            {
                _city = value;
            }
        }

        [SQLParameter(ColumnName = "POSTCODE", SQLDoWhat = SQLDoWhatEnum.Get)]
        [SQLParameter(ParameterName = "@POSTCODE", SQLDoWhat = SQLDoWhatEnum.Create, StoredProcedure = StoredProcedures.USP_ADDRESS_CREATE)]
        public string PostCode
        {
            get
            {
                return _postCode;
            }
            set
            {
                _postCode = value;
            }
        }

        [SQLParameter(IsClass = true, ColumnName = "STATE", SQLDoWhat = SQLDoWhatEnum.Get)]
        [SQLParameter(IsClass = true, SQLDoWhat = SQLDoWhatEnum.Create)]
        public State State
        {
            get
            {
                return _state;
            }
            set
            {
                _state = value;
            }
        }

        [SQLParameter(IsClass = true, ColumnName = "COUNTRY", SQLDoWhat = SQLDoWhatEnum.Get)]
        [SQLParameter(IsClass = true, SQLDoWhat = SQLDoWhatEnum.Create)]
        public Country Country
        {
            get
            {
                return _country;
            }
            set
            {
                _country = value;
            }
        }
        #endregion


        public override DatabaseInteractionDescriptor TableInteractionDescription()
        {
            DatabaseInteractionDescriptor desc = new DatabaseInteractionDescriptor();
            desc.CreateStoredProcedure = StoredProcedures.USP_ADDRESS_CREATE;
            return desc;
        }
    }
}